<!DOCTYPE html>
<html lang="zh-cn" >
<head>
    <title>数据交换单元状态日志</title>
    <#include "../../../__ref_common.ftl" parse=true/>
    <link rel="stylesheet" href="${mvcPath}/dacp-view/datastash/workshop/unit_state/css/common.css">
    <style>

    </style>
</head>
<body>
<div id="main" >
    <elx-content :location-origin="origin"  @end-load="endLoad" @back-href="backHref" :src="src" :type="type" :list-title="'数据交换单元状态日志'" :create-title="'数据交换单元任务状态日志'">
        <div slot="content" class="elx-row" style="width:100%;height:100%">
            <elx-header>
	            <el-form :model="unitStateLogFilter" :inline="true">
	                <el-form-item  label="处理单元" >
	                    <el-input v-model="unitStateLogFilter.unitCode" placeholder="请填写处理单元"></el-input>
	                </el-form-item>
	                <el-form-item  label="批次" >
	                    <el-input v-model="unitStateLogFilter.batchNo" placeholder="请填写批次"></el-input>
	                </el-form-item>
	                <el-form-item  label="是否翻牌" >
	                    <el-select v-model="unitStateLogFilter.isTurnover"  >
	                        <el-option v-for="item in turnOverEnum" :label="item.label" :value="item.value"></el-option>
	                    </el-select >
	                </el-form-item>
	                </el-form-item>
	                <el-form-item  label="状态" >
	                    <el-select v-model="unitStateLogFilter.state"  >
	                        <el-option v-for="item in stateEnum" :label="item.label" :value="item.value"></el-option>
	                    </el-select >
	                </el-form-item>
	                <el-form-item class="button-group">
	                    <el-button type="info" icon="search" @click.native="getUnitStateLog">查询</el-button>
	                </el-form-item>
	            </el-form>
            </elx-header>
            <elx-scroll-content ref="scrollContent" @resize="scrollContentResize">
                <el-table :data="unitStateLog"  v-loading="loading" border :height="tableHeight" style="width:100%" @expand="expand">
	                <el-table-column label="单元流水" prop="unitProcId" show-overflow-tooltip></el-table-column>
	                <el-table-column label="处理单元" prop="unitCode" width="74px" show-overflow-tooltip></el-table-column>
	                <el-table-column label="批次" prop="batchNo" width="80px" show-overflow-tooltip></el-table-column>
	                <el-table-column label="批次翻牌" prop="isTurnover"  width="74px" :formatter="turnOverFormatter"  show-overflow-tooltip></el-table-column>
	                <el-table-column label="任务数" width="60" prop="taskCnt" show-overflow-tooltip></el-table-column>
	                <el-table-column label="创建时间" prop="createDate" width="140" show-overflow-tooltip></el-table-column>
	                <el-table-column label="开始执行时间" prop="startDate"  width="140"  show-overflow-tooltip></el-table-column>
	                <el-table-column label="完成时间" prop="completeDate"  width="140"   show-overflow-tooltip></el-table-column>
<#--
	                <el-table-column label="更新时间" prop="lastupDate" width="150"  show-overflow-tooltip></el-table-column>
-->
                    <el-table-column
                            inline-template
                            align="center"
                            width="100"
                            label="状态">
                        <el-tag :type="row.state=='-1'?'danger':''"> <span v-html="stateFormatter(row)"></span> </el-tag>
                    </el-table-column>
	                <el-table-column label="执行信息" prop="message" show-overflow-tooltip></el-table-column>
	                <el-table-column label="操作" width="160" align="center">
	                    <template scope="scope">
                            <el-tooltip class="item" effect="light" content="查看" placement="top">
                                <el-button size="small"   @click="viewTaskStateLog(scope.row)"><i  class="uex-icon-view"></i> </el-button>
                            </el-tooltip>
                            <el-tooltip class="item" effect="light"  content="重做" placement="top">
                                <el-button size="small"   @click="oper(scope.row,'2')" ><i  class="uex-icon-rerun"></i> </el-button>
                            </el-tooltip>
                            <el-tooltip class="item" effect="light" v-if="scope.row.state=='-1'"  content="强制通过" placement="top">
                                <el-button size="small"   @click="oper(scope.row,'1')" ><i class="uex-icon-data-approval"></i> </el-button>
                            </el-tooltip>
                        </template>
	                </el-table-column>
	                <el-table-column type="expand">
				        <template scope="scope">
				            <el-table :data="scope.row.unitEventLog" border style="width:100%">
                                <el-table-column  type="index"   width="50">  </el-table-column>
			                    <el-table-column label="创建时间" prop="createDate"   width="150" show-overflow-tooltip></el-table-column>
			                    <el-table-column label="状态" prop="state"  width="100" :formatter="stateFormatter" show-overflow-tooltip></el-table-column>
			                    <el-table-column label="执行信息" prop="message" show-overflow-tooltip></el-table-column>
			                </el-table>
				        </template>
				    </el-table-column>
	            </el-table>
            </elx-scroll-content>
            <elx-footer v-show="unitStateLogFilter.total>unitStateLogFilter.pageSize">
                <div class="pagination-container">
	                <el-pagination
                        @current-change="handleCurrentChange"
                        :page-size="unitStateLogFilter.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :current-page="unitStateLogFilter.pageNum"
                        :total="unitStateLogFilter.total">
	                </el-pagination>
	            </div>
            </elx-footer>
        </div>
    <elx-content>
</div>
<script type="text/javascript">
    var vm = new Vue({
        el: '#main',
        data: function () {
            return {
            	type: 'list',
            	loading: false,
            	tableHeight: 0,
            	formLabelWidth: '120px',
            	origin: window.location.origin,
            	src:  _contextPath + '/datastash/workshop/unit/state',
                unitStateLog: [],
                unitStateLogFilter: {
                	unitCode: '',
                    batchNo: '',
                    isTurnover: '',
                    state: '',
                	pageNum: 1,
                    pageSize: 50,
                    total: 0
                },
                turnOverEnum:[
                    {label: '不翻', value: '0'},
                    {label: '翻', value: '1'}
                ],
                stateEnum:[
                    {label: '新建', value: '1'},
                    {label: '可运行', value: '2'},
                    {label: '正在运行', value: '3'},
                    {label: '资源阻塞', value: '4'},
                    {label: '依赖阻塞', value: '5'},
                    {label: '成功', value: '6'},
                    {label: '编译成功', value: '316'},
                    {label: '失败', value: '-1'}
                ],
            }
        },
        methods:{
        	scrollContentResize: function(size) {
        		this.tableHeight = size.innerHeight;
        	},
        	getUnitStateLog: function() {
        		var self = this;
        		var filter = JSON.parse(JSON.stringify(this.unitStateLogFilter));
        		filter.pageNum = filter.pageNum - 1;
                axios.get(_contextPath + '/open/datastash/unit/state/all',  {params: filter})
                .then(function (response) {
                    if (response.data) {
                    	var data = response.data;
                    	self.unitStateLog = _.map(data.content, function(item) {
                    		item.unitEventLog = [];
                    		return item;
                    	})
                        self.unitStateLogFilter.total = data.totalElements;
                        self.$nextTick(function() {
                        	self.$refs['scrollContent'].resize();
                        });
                    }
                })
                .catch(function(error) {
                });
        	},
        	getUnitEventLog: function(row, unitProcId) {
        		var _self = this;
        		axios.get(_contextPath + '/open/datastash/unit/state/eventlog',  {
        			params: {
        				unitProcId: unitProcId
        			}
        	    })
                .then(function(response) {
                    if (response.data) {
                    	row.unitEventLog = response.data.content;
                    }
                })
                .catch(function (error) {
                });
        	},
            handleCurrentChange: function(val) {
                this.stateLog.pageNum = val;
                this.getTableData();
            },
            expand: function(row, expanded) {
            	if (expanded) {
            		if (row.unitEventLog.length == 0) {
            			this.getUnitEventLog(row, row.unitProcId);
            		}
            	}
            },
            stateFormatter:function(val) {
                for(var i in this.stateEnum){
                    if( this.stateEnum[i].value==val.state){
                        return this.stateEnum[i].label;
                    }
                }
            },
            turnOverFormatter: function(val) {
                for (var i in this.turnOverEnum) {
                    if (this.turnOverEnum[i].value == val.isTurnover) {
                        return this.turnOverEnum[i].label;
                    }
                }
            },
            taskTypeFormatter: function(val) {
                for (var i in this.taskTypeEnum) {
                    if (this.taskTypeEnum[i].value == val.taskType) {
                        return this.taskTypeEnum[i].label;
                    }
                }
            },
            oper:function (item,operType) {
        	    var self=this;
                var _obj={unitProcId:item.unitProcId,unitCode:item.unitCode,oper:operType};
                axios.post(_contextPath+'/open/datastash/unit/inter', _obj)
                    .then(function (response) {
                    if (response.data.success == true) {
                        self.$message({
                            message: '操作成功',
                            type: 'success'
                        });
                        self.dialogFormVisible = false;
                    } else {
                        self.$message({
                            message: response.data.message,
                            type: 'error'
                        });
                    }
                }).catch(function (error) {
                    console.log(error);
                });



            },
            viewTaskStateLog: function(val) {
                this.src = _contextPath + '/datastash/workshop/unit/task/state/'+val.unitProcId;
                this.type = 'create';
            },
            endLoad: function() {
                this.src = '${mvcPath}/datastash/workshop/unit/state';
            },
            backHref: function() {
                this.getUnitStateLog();
                this.type = 'list';
            }
        },
        watch: {
        },
        created: function () {
            this.getUnitStateLog();
        }
    })
</script>
</body>
</html>